package animation5.view.zhaolixiang.com.viewanimation5

import android.animation.ArgbEvaluator
import android.animation.ValueAnimator
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val valueAnimator=ValueAnimator.ofInt(0,300)
        valueAnimator.duration=3000
        valueAnimator.addUpdateListener {
            animator->
            view.layout(view.left,
                    animator.animatedValue.toString().toInt(),
                    view.right,
                    animator.animatedValue.toString().toInt()+view.height)
        }
        //valueAnimator.interpolator=BounceInterpolator()
        //倒叙开始
       // valueAnimator.interpolator=MyLinearInterpolator()
        //valueAnimator.setEvaluator(MyIntEvaluator())
        //下面一句等效于上面两句
        valueAnimator.setEvaluator(MyReverseEvalutor())
        bt_begin.setOnClickListener{
            valueAnimator.start()
        }

        val colorValueAnimation=ValueAnimator.ofInt(0xffff0000.toInt(),0xff0000ff.toInt())
        colorValueAnimation.duration=5000
        colorValueAnimation.setEvaluator(ArgbEvaluator())
        colorValueAnimation.addUpdateListener {
            animator->
            view.setBackgroundColor(animator.animatedValue.toString().toInt())
        }
        bt_color.setOnClickListener{
            colorValueAnimation.start()
        }
    }
}
